package com.zzyl.generator.util;

import com.zzyl.common.constant.Constants;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.BufferedOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Properties;

public class VelocityTest  {
    public static void main(String[] args) throws IOException {

        Properties p = new Properties();
        //velocity资源加载器，告诉模板引擎到类路径下寻找资源（比如模板）
        p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        // 定义字符集
        p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8);
        //初始化velocity引擎
        Velocity.init(p);


        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put("TableName", "NursingPlan");
        velocityContext.put("tableName", "nursingPlan");
        velocityContext.put("pathName", "com.NursingPlan.Controller");
        velocityContext.put("author", "小新IP归属中国");


        Template template = Velocity.getTemplate("vms/controller.java.vm", "UTF-8");

        FileWriter fileWriter = new FileWriter("D:/controller.java");
        template.merge(velocityContext, fileWriter);

        fileWriter.close();
    }
}
